package vo;

import java.util.ArrayList;
import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.Transaction;

import util.HibernateUtil;

public class EntradaDAO {
	public Integer salvarEntrada(EntradaVO entrada) {

		Transaction transaction = null;

		Session session = HibernateUtil.currentSession();
		transaction = session.beginTransaction();

		Integer id = 0;
		if (entrada.getId() != 0) {
			session.saveOrUpdate(entrada);
		} else {
			id = (Integer) session.save(entrada);
		}

		transaction.commit();
		return id;
	}

	@SuppressWarnings("unchecked")
	public List<EntradaVO> consultarEntrada(EntradaVO entrada) {
		List<EntradaVO> listaDeEntrada = new ArrayList<EntradaVO>();

		Transaction transaction = null;

		Session session = HibernateUtil.currentSession();
		transaction = session.beginTransaction();

		Criteria criteria = session.createCriteria(EntradaVO.class);

		// if (entrada.getDescricao() != null &&
		// !entrada.getDescricao().equals("")) {
		// criteria.add(Restrictions.eq("descricao", produto.getDescricao()));
		// }

		listaDeEntrada = criteria.list();

		transaction.commit();
		return listaDeEntrada;
	}

	public void excluir(EntradaVO entrada) {
		Transaction transaction = null;

		Session session = HibernateUtil.currentSession();
		transaction = session.beginTransaction();

		session.delete(entrada);

		transaction.commit();
	}

}

// }
